package com.example.swd1.gudong.main.user.mymedal;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.swd1.gudong.R;

import java.util.List;

/**
 * Created by user on 9/14/16.
 */
public class MedalGridAdapter extends BaseAdapter {
    private Context context;
    private List<int[]> datas;

    public MedalGridAdapter(Context context, List<int[]> ints) {
        this.context = context;
        this.datas = ints;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder=new ViewHolder();
            convertView = View.inflate(context, R.layout.item_grid_view_medal, null);
            viewHolder.icon= (ImageView) convertView.findViewById(R.id.item_medal_grid_icon);
            viewHolder.text = (TextView) convertView.findViewById(R.id.item_medal_grid_text);
            convertView.setTag(viewHolder);
        }
        int[] data = datas.get(position);
        viewHolder= (ViewHolder) convertView.getTag();
        viewHolder.icon.setImageResource(data[0]);
        viewHolder.text.setText(data[1]);
        return convertView;
    }

    class ViewHolder {
        private ImageView icon;
        private TextView text;
    }
}
